<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="空调类型">
      <el-select v-model="form.type" placeholder="请选择空调类型">
        <el-option label="格力" value="格力"></el-option>
        <el-option label="美的" value="美的"></el-option>
        <el-option label="其他" value="其他"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item class="el-form-item-label-cover" label="空调故障码">
      <el-input class="el-input-item-cover" v-model="form.code"></el-input>
    </el-form-item>

    <el-form-item class="el-form-item-label-cover" label="故障原因">
      <el-input
        class="el-input-item-cover"
        v-model="form.speculateReason"
      ></el-input>
    </el-form-item>

    <el-form-item class="el-form-item-label-cover" label="维修建议">
      <el-input
        class="el-input-item-cover"
        v-model="form.repairReco"
      ></el-input>
    </el-form-item>

    <el-form-item>
      <el-button class="button-cover" type="primary" @click="onSubmit">故障推测</el-button>
      <el-button class="button-cover" type="primary" @click="onSubmitOrder">创建维修订单</el-button>

    </el-form-item>


  </el-form>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      labelPosition: "top",
      form: {
        code: "",
        type: "",
        date1: "",
        date2: "",
        delivery: false,
        resource: "",
        desc: "",
        speculateReason: "",
        repairReco: "",
        user:JSON.parse(localStorage.getItem("user"))
      },
    };
  },
  methods: {
    onSubmit() {
      axios({
        method: 'post',
        url: 'http://localhost:9090/selfcheck/check',
        headers:{
            token:this.form.user.token
        },
        data: {
          airCondType: this.form.type,
          airCondCode: this.form.code,
          speculateReason: "",
          repairReco: "",
        },
        
      })
        .then((res) => {
          console.log(res);
          console.log("post成功，data:",res.data.data);
        this.form.speculateReason=res.data.data.speculateReason
        this.form.repairReco=res.data.data.repairReco

        })
        .catch((err) => {
          console.log(err);
          console.log("post失败");
        });
    },

    onSubmitOrder() {
      console.log(this.form.type);
      console.log(this.form.code);
    var user=JSON.parse(localStorage.getItem(user));
      
      axios({
        method: 'post',
        url: 'http://localhost:9090/order/create',
        headers:{
            token:this.form.user.token
        },
        data: {
          airCondType: this.form.type,
          airCondCode: this.form.code,
          speculateReason: this.form.speculateReason,
          repairReco: this.form.repairReco,
        },
        
      })
        .then((res) => {
          console.log("post成功，data:",res.data.data);
          this.$message({
          message: '订单创建成功',
          type: 'success'
        });
        this.form.speculateReason=res.data.data.speculateReason
        this.form.repairReco=res.data.data.repairReco

        })
        .catch((err) => {
          console.log(err);
          console.log("post失败");
        });
    },
  },
};
</script>

<style>
.headerBg {
  background: #ccc !important;
}
.el-input-item-cover {
  width: 215px;
}
.button-cover{
    width: 100px;
}
</style>
